home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / qbsnip.zip / LED.BAS < prev    next >
BASIC Source File  |  1997-06-20  |  4KB  |  106 lines

  1. DEFINT A-Z
  2.  
  3. 'LedDisplay() routine Original Author: Scott Pessoni - August 1995
  4. '---> Modified by Jonathan Leger <---
  5.  
  6. 'All other code, including InitLedDisplay() and InitLedBar(), written
  7. 'by Jonathan Leger (leger@mail.dtx.net).
  8.  
  9. DECLARE SUB LedDisplay (x%, y%, c0%, c1%, digits%, n#)
  10. DECLARE SUB LedBar (x%, y%, c1%, c0%, e%, m%, n#)
  11.  
  12. SCREEN 7
  13.  
  14. '****** LedBar x%, y%, c1%, c0%, e%, m%, n#
  15. ' x, y is pixel location to place LED Bar
  16. ' c0 is the color of the LEDs when turned off*
  17. ' c1 is the color of the LEDs when turned on*
  18. ' e is the number of LEDs to put in the bar
  19. ' m is the maximum number of LEDs lit when bar is at 100%
  20. ' n is the number of LEDs to light up
  21. ' * This screen mode in the demo uses the standard 16 colors 0 - 15.
  22.  
  23. 'LedBar  x,   y,  c1,c0,  e,  m, n#
  24.  LedBar 100, 100, 10, 8, 10, 10, 4      'Audio Bar?
  25.  
  26. '****** LedDisplay (x%, y%, c0%, c1%, digits%, n#)
  27. ' x, y is pixel location to place LED Bar
  28. ' c0 is the color of the LEDs when turned off*
  29. ' c1 is the color of the LEDs when turned on*
  30. ' digits is the number of LED units to show (total)
  31. ' n what number you would like the LED to show
  32. ' * This screen mode in the demo uses the standard 16 colors 0 - 15.
  33.  
  34. 'LedDisplay  x,   y, c0, c1, digits, n#)
  35.  LedDisplay 100, 60, 8, 12, 3, 27
  36. 'The above set up a 3 digit display showing the number 27 in red (lit)
  37.  
  38. Pause$ = INPUT$(1): SCREEN 0: WIDTH 80: COLOR 7, 0: CLS : END
  39.  
  40. SUB LedBar (x%, y%, c1%, c0%, e%, m%, n#)
  41. 'LedBar: A simulated Led Bargraph
  42.  
  43. IF n# < 0 THEN
  44.   FOR i = 1 TO e% * 2 STEP 2
  45.     LINE (x% + i, y%)-(x% + i, y% + 5), c0%
  46.   NEXT
  47.   EXIT SUB
  48. END IF
  49. j = INT(n# * e% / m%): IF j > e% THEN j = e%
  50. FOR i = 1 TO j * 2 STEP 2
  51.   LINE (x% + i, y%)-(x% + i, y% + 5), c1%
  52. NEXT
  53. FOR i = j * 2 + 1 TO e% * 2 STEP 2
  54.   LINE (x% + i, y%)-(x% + i, y% + 5), c0%
  55. NEXT
  56.  
  57. END SUB
  58.  
  59. SUB LedDisplay (x%, y%, c0%, c1%, digits%, n#)
  60. 'LedDisplay: Generates a simulated Digital Led Display.
  61.  
  62. n# = FIX(n#): n# = VAL(LEFT$(STR$(n#), digits% + 1)): p = x%
  63. IF LEN(STR$(n#)) - 1 < digits% THEN  'Clear Unused digits
  64.   FOR ced = 1 TO digits% - (LEN(STR$(n#)) - 1)
  65.     LINE (p + 1, y%)-(p + 5, y%), c0%: LINE (p, y% + 1)-(p, y% + 5), c0%
  66.     LINE (p + 6, y% + 1)-(p + 6, y% + 5), c0%
  67.     LINE (p + 1, y% + 6)-(p + 5, y% + 6), c0%
  68.     LINE (p, y% + 7)-(p, y% + 11), c0%
  69.     LINE (p + 6, y% + 7)-(p + 6, y% + 11), c0%
  70.     LINE (p + 1, y% + 12)-(p + 5, y% + 12), c0%: p = p + 8
  71.   NEXT ced
  72. END IF
  73. FOR t = 1 TO LEN(STR$(n#)) - 1
  74.   w$ = MID$(STR$(n#), t + 1, 1)
  75.   SELECT CASE w$ 'Find and select which elements to turn on
  76.     CASE "0"
  77.       E1 = c1%: E2 = c1%: E3 = c1%: E4 = c0%: E5 = c1%: E6 = c1%: E7 = c1%
  78.     CASE "1"
  79.       E1 = c0%: E2 = c0%: E3 = c1%: E4 = c0%: E5 = c0%: E6 = c0%: E7 = c1%
  80.     CASE "2"
  81.       E1 = c0%: E2 = c1%: E3 = c1%: E4 = c1%: E5 = c1%: E6 = c1%: E7 = c0%
  82.     CASE "3"
  83.       E1 = c0%: E2 = c1%: E3 = c1%: E4 = c1%: E5 = c0%: E6 = c1%: E7 = c1%
  84.     CASE "4"
  85.       E1 = c1%: E2 = c0%: E3 = c1%: E4 = c1%: E5 = c0%: E6 = c0%: E7 = c1%
  86.     CASE "5"
  87.       E1 = c1%: E2 = c1%: E3 = c0%: E4 = c1%: E5 = c0%: E6 = c1%: E7 = c1%
  88.     CASE "6"
  89.       E1 = c1%: E2 = c0%: E3 = c0%: E4 = c1%: E5 = c1%: E6 = c1%: E7 = c1%
  90.     CASE "7"
  91.       E1 = c0%: E2 = c1%: E3 = c1%: E4 = c0%: E5 = c0%: E6 = c0%: E7 = c1%
  92.     CASE "8"
  93.       E1 = c1%: E2 = c1%: E3 = c1%: E4 = c1%: E5 = c1%: E6 = c1%: E7 = c1%
  94.     CASE "9"
  95.       E1 = c1%: E2 = c1%: E3 = c1%: E4 = c1%: E5 = c0%: E6 = c0%: E7 = c1%
  96.   END SELECT
  97.   LINE (p, y% + 1)-(p, y% + 5), E1: LINE (p + 1, y%)-(p + 5, y%), E2
  98.   LINE (p + 6, y% + 1)-(p + 6, y% + 5), E3
  99.   LINE (p + 1, y% + 6)-(p + 5, y% + 6), E4: LINE (p, y% + 7)-(p, y% + 11), E5
  100.   LINE (p + 1, y% + 12)-(p + 5, y% + 12), E6
  101.   LINE (p + 6, y% + 7)-(p + 6, y% + 11), E7: p = p + 8
  102. NEXT t
  103.  
  104. END SUB
  105.  
  106.